package com.zhangshuo.common.shiro;

import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;

import java.util.Collection;
import java.util.Collections;
import java.util.Set;

/**
 * Created by Administrator on 2017/6/2 0002.
 * 自定义的ShiroCache，其实与Spring中的RedisCache基本类型，不用自己去实现了，直接使用原有的方法即可
 */
public class ShiroCache<K,V> implements Cache<K,V> {

    private org.springframework.cache.Cache cache ;

    public ShiroCache(org.springframework.cache.Cache cache){
        this.cache = cache;
    }
    private ShiroCache(){}

    @Override
    public V get(K key) throws CacheException {
        return cache.get(key)==null? null : (V)cache.get(key).get();
    }

    @Override
    public V put(K key, V value) throws CacheException {
        cache.put(key,value);
        return value;
    }

    @Override
    public V remove(K key) throws CacheException {
        V value = get(key);
        cache.evict(key);
        return value;
    }

    @Override
    public void clear() throws CacheException {
        cache.clear();
    }

    @Override
    public int size() {
        return 0;
    }

    @Override
    public Set keys() {
        return null;
    }

    @Override
    public Collection values() {
        return Collections.EMPTY_SET;
    }


}
